Add reliability diagnostics to GVar#8
Merged
Merged
Conversation
A GVar's moments are exact only when each operation is at most quadratic
over the spread of its input and the input really is Gaussian. Neither
holds in general. GVar now carries two fields that accumulate through
arithmetic and say how far the result has drifted from a Gaussian:
κ3 the third cumulant, exposed standardized as `skewness`
err an estimate of the absolute error in `center`, exposed as
`moment_error`, tracking the leading Taylor term each operation
neglects
`distrust` combines them into one dimensionless number: the displacement
of the quantiles in units of `rad`. It is zero for an exact Gaussian and
grows without bound as the description degrades. The two components are
complementary. `exp` of a Gaussian is exactly lognormal, so its
`moment_error` is zero while its skewness is large; a quadratic has
neither.
Two fixes fall out of the same derivation:
Var[f(x)] = f'^2 σ^2 + f''^2 σ^4/2 + f' f''' σ^4 + O(σ^6). The third term
was omitted although it is the same order as the second, and it is
positive for `inv`, `log`, `sqrt` and `x^p`, so σ was systematically
understated: `log(3 ± 0.5)` was low by 3.1%, now 0.5%.
ThickNumbers builds the result of `hull`, `intersect`, `typemin` and
`typemax` with the two-argument call `TN(lo, hi)`, but `GVar(center, σ)`
is a different parametrization; those four now have GVar methods. The
generic versions produced a hull spanning [-2.5, 6.5] for operands
spanning [2, 4] and [2.5, 4.5], and an intersection wider than either
operand.
Integer powers use exact Gaussian raw moments, which terminate for a
polynomial, rather than an asymptotic correction to the variance. Mean,
variance and third cumulant are then all exact, and SpecialFunctions is
no longer needed. Exponents above 20 overflow the moment sum and throw.
Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
ThickNumbers 1.1.2 builds generic results with `lohi` and `midrad` rather than with a two-argument `TN(lo, hi)` call, so `GVar`'s midpoint/σ parametrization no longer needs its own `typemin` and `typemax`. `hull` and `intersect` stay, for a different reason: a result built from the span alone carries the diagnostics of a fresh box, so the generic versions would report `distrust` of zero for the hull of two values that are not to be trusted at all. Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
0cab54d to
ce246b6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8 +/- ##
===========================================
+ Coverage 38.70% 66.66% +27.95%
===========================================
Files 1 1
Lines 124 168 +44
===========================================
+ Hits 48 112 +64
+ Misses 76 56 -20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A GVar's moments are exact only when each operation is at most quadratic over the spread of its input and the input really is Gaussian. Neither holds in general. GVar now carries two fields that accumulate through arithmetic and say how far the result has drifted from a Gaussian:
κ3 the third cumulant, exposed standardized as
skewnesserr an estimate of the absolute error incenter, exposed asmoment_error, tracking the leading Taylor term each operationneglects
distrustcombines them into one dimensionless number: the displacement of the quantiles in units ofrad. It is zero for an exact Gaussian and grows without bound as the description degrades. The two components are complementary.expof a Gaussian is exactly lognormal, so itsmoment_erroris zero while its skewness is large; a quadratic has neither.Two fixes fall out of the same derivation:
Var[f(x)] = f'^2 σ^2 + f''^2 σ^4/2 + f' f''' σ^4 + O(σ^6). The third term was omitted although it is the same order as the second, and it is positive for
inv,log,sqrtandx^p, so σ was systematically understated:log(3 ± 0.5)was low by 3.1%, now 0.5%.ThickNumbers builds the result of
hull,intersect,typeminandtypemaxwith the two-argument callTN(lo, hi), butGVar(center, σ)is a different parametrization; those four now have GVar methods. The generic versions produced a hull spanning [-2.5, 6.5] for operands spanning [2, 4] and [2.5, 4.5], and an intersection wider than either operand.Integer powers use exact Gaussian raw moments, which terminate for a polynomial, rather than an asymptotic correction to the variance. Mean, variance and third cumulant are then all exact, and SpecialFunctions is no longer needed. Exponents above 20 overflow the moment sum and throw.
Assisted-by: Claude Opus 4.8 noreply@anthropic.com